package com.zerosky.crm.controller;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.logging.log4j.util.Strings;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.servlet.ModelAndView;

import com.zerosky.crm.po.Activity;
import com.zerosky.crm.po.Contract;
import com.zerosky.crm.po.Customer;
import com.zerosky.crm.po.CustomerFollowRecords;
import com.zerosky.crm.po.Department;
import com.zerosky.crm.po.Document;
import com.zerosky.crm.po.EarningRecord;
import com.zerosky.crm.po.Employee;
import com.zerosky.crm.po.Invite;
import com.zerosky.crm.po.Pluralize;
import com.zerosky.crm.po.Product;
import com.zerosky.crm.po.ReturnRecord;
import com.zerosky.crm.po.VisitRecord;
import com.zerosky.crm.service.ActivityService;
import com.zerosky.crm.service.ContractService;
import com.zerosky.crm.service.CustomerFollowRecordsService;
import com.zerosky.crm.service.CustomerService;
import com.zerosky.crm.service.DepartmentService;
import com.zerosky.crm.service.DocumentService;
import com.zerosky.crm.service.EarningRecordService;
import com.zerosky.crm.service.EmployeeService;
import com.zerosky.crm.service.InviteService;
import com.zerosky.crm.service.PluralizeService;
import com.zerosky.crm.service.ProductService;
import com.zerosky.crm.service.ReturnRecordService;
import com.zerosky.crm.service.VisitRecordService;
import com.zerosky.crm.util.BaseAction;
import com.zerosky.crm.util.MyFileUploadUtils;
import com.zerosky.crm.util.PageInfo;

@Controller
public class CustomerController extends BaseAction {
	private Logger logger = LoggerFactory.getLogger(CustomerController.class); // 日志

	@Resource(name = "customerService")
	private CustomerService customerService;

	@Resource(name = "visitRecordService")
	private VisitRecordService visitRecordService;

	@Resource(name = "customerFollowRecordsService")
	private CustomerFollowRecordsService customerFollowRecordsService;

	@Resource(name = "contractService")
	private ContractService contractService;

	@Resource(name = "earningRecordService")
	private EarningRecordService earningRecordService;

	@Resource(name = "returnRecordService")
	private ReturnRecordService returnRecordService;

	@Resource(name = "productService")
	private ProductService productService;

	@Resource(name = "activityService")
	private ActivityService activityService;

	@Resource(name = "inviteService")
	private InviteService inviteService;

	@Resource(name = "employeeService")
	private EmployeeService employeeService;

	@Resource(name = "departmentService")
	private DepartmentService departmentService;

	@Resource(name = "pluralizeService")
	private PluralizeService pluralizeService;

	@Resource(name = "documentService")
	private DocumentService documentService;

	/**
	 * 跳转员工的客户界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toEmployeeCustomer.do")
	public ModelAndView toEmployeeCustomer(HttpServletRequest request, HttpSession session,
			HttpServletResponse response, String id) throws Exception {
		if (checkPower(session, 90)) {
			request.setAttribute("employeeId", id);
			return new ModelAndView("WEB-INF/jsp/highseaspool/customerList");
		} else {
			return new ModelAndView("WEB-INF/jsp/error/404");
		}
	}

	/**
	 * 跳转全部员工客户数量统计界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toHighSeasPoolAllList.do")
	public ModelAndView highSeasPoolAllList(HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		Employee user = (Employee) session.getAttribute("loginUser");
		if (checkPower(session, 90)) {
			Map<String, Object> map = new HashMap<>();
			map.put("canNotReadAllMessage", false);
			List<Department> listDept = departmentService.getDepartmentList(map);
			List<Department> list = new ArrayList<Department>();
			if (user.getQuarters().equals("5") || user.getQuarters().equals("6")) {
				Department dept = new Department();
				dept.setDeptName("-请选择分公司-");
				list.add(dept);
				for (int i = 1; i <= listDept.size(); i++) {
					list.add(listDept.get(i - 1));
				}

			} else {
				map.put("employeeId", user.getEmployeeId());
				List<Pluralize> pluralizeList = pluralizeService.getPluralizeList(map);
				if (!user.getQuarters().equals("7") && !user.getQuarters().equals("8")) {
					list.add(user.getDept());
				}
				for (Pluralize pluralize : pluralizeList) {
					for (Department dept : listDept) {
						if (!pluralize.getDeptId().equals(user.getDept().getDeptId())) {
							if (pluralize.getDeptId().equals(dept.getDeptId())) {
								list.add(dept);
							}
						}
					}
				}
			}
			request.setAttribute("dept", list);
			return new ModelAndView("WEB-INF/jsp/highseaspool/highseaspoolAllList");
		} else {
			return new ModelAndView("WEB-INF/jsp/error/404");
		}
	}

	/**
	 * 跳转客户详情界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toCustomerMaterial.do")
	public ModelAndView customerMaterial(HttpServletRequest request, HttpSession session, HttpServletResponse response)
			throws Exception {
		if (checkPower(session, 89)) {
			Map<String, Object> map = new HashMap<>();
			map.put("canNotReadAllMessage", false);
			List<Department> list = departmentService.getDepartmentList(map);
			request.setAttribute("dept", list);
			return new ModelAndView("WEB-INF/jsp/customer/customerMaterialList");
		} else {
			return new ModelAndView("WEB-INF/jsp/error/404");
		}
	}

	/**
	 * 获取全部活动信息
	 * 
	 * @return
	 */
	@RequestMapping("/getActivityListInfo.do")
	@ResponseBody
	public Map<String, Object> getActivityListInfo(HttpSession session) {
		Map<String, Object> json = new HashMap<String, Object>();
		List<Activity> activityList = null;
		try {
			Employee emp = (Employee) session.getAttribute("loginUser");
			if (emp == null) {
				json.put("code", -2);// session失效、
				return json;
			}
			Map<String, Object> map = new HashMap<String, Object>();
			if (!checkPower(session, 67)) {
				map.put("deptId", emp.getDept().getDeptId());
				if (emp.getBranch() != null) {
					map.put("branchId", emp.getBranch().getBranchId());
				}
			}
			activityList = activityService.getActivityList(map);// 查询全部有效活动信息

			json.put("code", 0);
			json.put("data", activityList);

		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 获取其他部门客户数
	 * 
	 * @return
	 */
	@RequestMapping("/getOtherCustomer.do")
	@ResponseBody
	public Map<String, Object> getOtherCustomer(HttpSession session, String deptId, String branchId, Integer limit,
			Integer page) {
		Map<String, Object> json = new HashMap<String, Object>();
		PageInfo<Customer> pageInfo = new PageInfo<Customer>();// 定义一个工具类
		Map<String, Object> map = new HashMap<String, Object>();
		Employee user = (Employee) session.getAttribute("loginUser");
		try {
			if (user.getQuarters().equals("1")) {
				map.put("fkDeptId", "10");
			} else if (user.getQuarters().equals("2")) {
				map.put("fkDeptId", "10");
			} else {
				map.put("fkDeptId", deptId);
			}
			map.put("branchId", branchId);
			pageInfo.setPageNo(page);
			pageInfo.setPageSize(limit);
			pageInfo = customerService.getOtherDeptCustomerNumber(map, pageInfo);
			if (!user.getQuarters().equals("1") && !user.getQuarters().equals("2")) {
				json.put("CustomerSumCount", customerService.getOtherDeptCustomerNumberSum(map));
			}
			json.put("total", pageInfo.getPageCount());
			json.put("data", pageInfo.getList());
			json.put("flag", 1);
		} catch (Exception e) {
			json.put("flag", -1);
			json.put("msg", "系统出现异常!");
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 请求所有同部门的员工信息和自己所有的客户
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/askEmployee.do")
	@ResponseBody
	public Map<String, Object> askEmployee(HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户信息
		Map<String, Object> map = new HashMap<String, Object>();// 定义条件集合
		try {
			/*
			 * 暂未定义查询属于自己的客户信息
			 */
			// map.put("deptId", user.getDept().getDeptId());// 为自己部门的人
			map.put("personLiable", user.getEmployeeId());
			PageInfo<Employee> page = employeeService.getEmployeeList(json);
			List<Customer> list = customerService.getCustomerList(map);
			json.put("data", page.getList());
			json.put("list", list);
			json.put("code", "1");

		} catch (Exception e) {
			json.put("code", "-1");
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 删除市场活动信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/delActivity.do")
	@ResponseBody
	public Map<String, Object> delActivity(String id, HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {
			activityService.deleteActivityById(id);
			json.put("code", 1);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 跳转系统管理市场活动界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toSystemActivity.do")
	public ModelAndView updateActivity(HttpServletRequest request, HttpSession session, HttpServletResponse response) {
		try {
			if (checkPower(session, 67)) {
				Map<String, Object> map = new HashMap<>();
				map.put("canNotReadAllMessage", false);
				List<Department> list = new ArrayList<Department>();
				List<Department> listDept = new ArrayList<Department>();
				Department dept = new Department();
				listDept = departmentService.getDepartmentList(map);
				dept.setDeptName("全部分公司");
				dept.setRemake("滨海金控");
				list.add(dept);
				for (int i = 1; i <= listDept.size(); i++) {
					list.add(listDept.get(i - 1));
				}
				request.setAttribute("dept", list);
				return new ModelAndView("WEB-INF/jsp/system/activityList");
			} else {
				return new ModelAndView("/WEB-INF/jsp/error/404");
			}
		} catch (Exception e) {
			logger.error("获取数据失败，原因：" + e);
			return new ModelAndView("/WEB-INF/jsp/error/500");
		}
	}

	/**
	 * 跳转添加市场活动界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toActivity.do")
	public ModelAndView addActivity(HttpServletRequest request, HttpSession session, HttpServletResponse response)
			throws Exception {
		return new ModelAndView("WEB-INF/jsp/activityList");
	}

	/**
	 * 获取活动列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/activityList.do")
	@ResponseBody
	public Map<String, Object> activityList(Integer id, Integer limit, Integer page, String activityTitle,
			HttpServletRequest request, HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		Employee user = (Employee) session.getAttribute("loginUser");
		PageInfo<Activity> pageInfo = new PageInfo<Activity>();
		try {
			pageInfo.setPageNo(page);
			pageInfo.setPageSize(limit);
			if (Strings.isNotEmpty(activityTitle)) {// 条件查询
				param.put("activityName", activityTitle);
			}
			if (!checkPower(session, 67)) {
				param.put("deptId", user.getDept().getDeptId());
				if (user.getBranch() != null) {
					param.put("branchId", user.getBranch().getBranchId());
				}
			}
			json.put("flag", "0");
			PageInfo<Activity> pageRole = activityService.getPageInfoActivityList(param, pageInfo);
			// for (int i = 0; i < pageRole.getList().size(); i++) {
			// if (user.getQuarters().equals("0")) {
			// pageRole.getList().get(i).setStatus("0");
			// } else {
			// pageRole.getList().get(i).setStatus("1");
			// }
			// }
			json.put("total", pageRole.getPageCount());
			json.put("data", pageRole.getList());
			json.put("flag", 1);
			logger.info("查询活动列表信息");
		} catch (Exception e) {
			json.put("flag", -1);
			logger.error("查询活动列表失败：" + e);
		}
		return json;

	}

	/**
	 * 请求编辑市场活动信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/editActivity.do")
	@ResponseBody
	public Map<String, Object> editActivity(String id, HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		try {
			Activity activity = activityService.getActivityById(id);
			Invite invite = inviteService.getStatisticalMagnitude(Integer.parseInt(id));
			json.put("invite", invite);
			json.put("activity", activity);
			json.put("code", 1);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 添加市场活动信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/insertActivity.do")
	@ResponseBody
	public Map<String, Object> insertActivity(Activity activity, String date1, String date2, String oper,
			HttpServletRequest request, HttpSession session, HttpServletResponse response) throws Exception {
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		try {
			// 格式化时间
			SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
			if (date1 != null && !date1.equals("")) {
				activity.setStartDate(formatter.parse(date1));
			}
			if (date2 != null && !date2.equals("")) {
				activity.setEndDate(formatter.parse(date2));
			}
			if (oper.equals("新增")) {
				activity.setCreatePeople(user.getName());
				activity.setCreateDate(new Date());
				activity.setDeptName(user.getDept().getDeptName());
			}
			activityService.saveActivity(activity, oper);
			json.put("code", 1);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 跳转合同选项合同信息界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toContractList.do")
	public ModelAndView toContractList(HttpSession session) throws Exception {
		return new ModelAndView("WEB-INF/jsp/contract/contractList");

	}

	/**
	 * 跳转审核合同列表界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toContractCheckList.do")
	public ModelAndView toContractCheckList(HttpSession session, HttpServletRequest request) throws Exception {
		// 获取登录用户信息
		//Employee user = (Employee) session.getAttribute("loginUser");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("status", 0);// 查询属于自己的信息
		//map.put("personLiable", user.getEmployeeId());// 查询属于自己的信息
		//List<Customer> list = customerService.getCustomerList(map);
		//List<Product> productList = productService.getProductList(map);// 获取所有产品信息
		//request.setAttribute("productList", productList);
		//request.setAttribute("customerList", list);
		return new ModelAndView("WEB-INF/jsp/contract/contractCheckList");
	}

	/**
	 * 跳转合同到期提醒页面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toContractExpiringList.do")
	public ModelAndView toContractExpiringList(HttpSession session, HttpServletRequest request) throws Exception {
		return new ModelAndView("WEB-INF/jsp/contract/contractExpiringList");
	}

	/**
	 * 跳转合同返利提醒页面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toContractRebateList.do")
	public ModelAndView toContractRebateList(HttpSession session, HttpServletRequest request) throws Exception {
		return new ModelAndView("WEB-INF/jsp/contract/contractRebateList");
	}

	/**
	 * 获取合同的合同信息列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/contract.do")
	@ResponseBody
	public Map<String, Object> contract(String id, String userId, Integer limit, Integer page, String contractNum,
			String contractEndDate, String isRebate, String contractStatus, HttpServletRequest request,
			HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户信息
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		PageInfo<Contract> pageInfo = new PageInfo<Contract>();
		try {
			if (userId == null || "-1".equals(userId)) {
				userId = user.getEmployeeId();
			}
			// 如果查询到期合同数据标记不为空，添加查询标记
			if (contractEndDate != null) {
				param.put("contractEndDate", 1);
			}
			// 如果查询返利合同数据标记不为空，添加查询标记
			if (isRebate != null) {
				param.put("isRebate", 1);
			}
			param.put("employeeId", userId);// 属于那个员工的合同
			param.put("customerId", id);// 属于那个客户的合同
			pageInfo.setPageNo(page);
			pageInfo.setPageSize(limit);
			if (Strings.isNotEmpty(contractNum)) {// 条件查询
				param.put("contractNum", contractNum);
			}
			if (Strings.isNotEmpty(contractStatus)) {// 条件查询
				param.put("contractStatus", contractStatus);
			}
			json.put("flag", "0");
			PageInfo<Contract> pageRole = contractService.getPageInfoList(param, pageInfo);
			json.put("total", pageRole.getPageCount());
			json.put("data", pageRole.getList());
			json.put("flag", 1);

		} catch (Exception e) {
			json.put("flag", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 跳转合同选项添加合同信息界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/addContractList.do")
	public ModelAndView addContractList(HttpServletRequest request, HttpSession session, HttpServletResponse response)
			throws Exception {
		// 获取登录用户信息
		Employee user = (Employee) session.getAttribute("loginUser");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("personLiable", user.getEmployeeId());// 查询属于自己的信息
		List<Customer> list = customerService.getCustomerList(map);
		List<Product> productList = productService.getProductList(map);// 获取所有产品信息
		request.setAttribute("productList", productList);
		request.setAttribute("customerList", list);
		return new ModelAndView("WEB-INF/jsp/contract/addContract");
	}

	/**
	 * 添加客户回款信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/insertEarningRecord.do")
	@ResponseBody
	public Map<String, Object> insertEarningRecord(EarningRecord earningRecord, String date, HttpServletRequest request,
			HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {
			// 获取登录用户
			Employee user = (Employee) session.getAttribute("loginUser");
			earningRecord.setEarningRecordId(UUID.randomUUID().toString());
			// 获取合同信息
			Contract contract = contractService.getContractById(earningRecord.getContractId());
			earningRecord.setContractNum(contract.getContractNum());
			earningRecord.setEmployeeId(user.getEmployeeId());
			if (date != null && !date.equals("")) {
				earningRecord.setTakeInterest(stringToDateTime(date));
			}
			earningRecord.setCreateDate(new Date());
			earningRecord.setCreatePeople(user.getName());
			earningRecord.setSection(user.getDept().getDeptId());
			earningRecordService.saveEarningRecord(earningRecord, "新增");
			json.put("code", 1);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 跳转添加客户回款界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/addEarningRecord.do")
	public ModelAndView addEarningRecord(HttpServletRequest request, HttpSession session, HttpServletResponse response)
			throws Exception {
		// 获取登录用户信息
		Employee user = (Employee) session.getAttribute("loginUser");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("personLiable", user.getEmployeeId());// 查询属于自己信息
		List<Customer> list = customerService.getCustomerList(map);
		map.put("employeeId", user.getEmployeeId());// 根据用户ID和客户ID获取相关合同信息
		List<Contract> contractList = contractService.getContractList(map);
		request.setAttribute("contractList", contractList);
		request.setAttribute("customerList", list);
		return new ModelAndView("WEB-INF/jsp/customer/addEarning");
	}

	/**
	 * 添加合同登记记录
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/insertContract.do")
	@ResponseBody
	public Map<String, Object> insertContract(Contract contract, String date1, String date2, HttpServletRequest request,
			HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {
			// 获取登录用户
			Employee user = (Employee) session.getAttribute("loginUser");
			contract.setContractId(UUID.randomUUID().toString());// 获取UUID
			if (date1 != null && !date1.equals("")) {
				contract.setTradeDate(stringToDate(date1));// 获取开始日期
			}
			if (date2 != null && !date2.equals("")) {
				contract.setEndDate(stringToDate(date2));// 获取结束日期
			}
			contract.setEmployeeId(user.getEmployeeId());
			contract.setCreateDate(new Date());
			contract.setCreatePeople(user.getName());
			contract.setDeptId(user.getDept().getDeptId());
			contract.setStatus("0");
			contractService.saveContract(contract, "新增", user);
			json.put("code", 1);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 跳转添加合同登记界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/addContract.do")
	@ResponseBody
	public Map<String, Object> addContract(String id, HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {
			// 获取登录用户信息
			Employee user = (Employee) session.getAttribute("loginUser");
			Map<String, Object> map = new HashMap<String, Object>();
			/*
			 * 暂未定义查询属于自己的客户信息
			 */
			map.put("personLiable", user.getEmployeeId()); // 查询属于自己的信息
			List<Customer> list = customerService.getCustomerList(map);
			List<Product> plist = productService.getProductList(map);
			json.put("product", plist);
			json.put("customer", list);
			json.put("code", 1);
		} catch (Exception e) {
			logger.error("获取数据失败，原因：" + e);
			json.put("code", -1);
		}
		return json;
	}

	/**
	 * 跳转客户的回访记录界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toReturn.do")
	public ModelAndView toReturn(HttpServletRequest request, HttpSession session, String id) throws Exception {
		request.setAttribute("customerId", id);
		return new ModelAndView("WEB-INF/jsp/customer/returnRecordList");

	}

	/**
	 * 跳转经理查看员工客户的回访记录界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toEmployeeReturn.do")
	public ModelAndView toEmployeeReturn(HttpServletRequest request, HttpSession session, String id) throws Exception {
		request.setAttribute("empId", id);
		return new ModelAndView("WEB-INF/jsp/employee/returnRecordList");

	}

	/**
	 * 添加客户回访信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/insertReturn.do")
	@ResponseBody
	public Map<String, Object> insertReturnRecord(ReturnRecord returnRecord, String date, HttpServletRequest request,
			HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {
			// 获取登录用户
			Employee user = (Employee) session.getAttribute("loginUser");
			returnRecord.setReturnEmpId(user.getEmployeeId());
			returnRecord.setCreatePeople(user.getName());
			returnRecord.setCreateDate(new Date());
			returnRecord.setSection(user.getDept().getDeptId());
			if (date != null && !date.equals("")) {
				returnRecord.setReturnDate(stringToDateTime(date));
			}
			returnRecordService.saveReturnRecord(returnRecord, "新增");
			json.put("code", 1);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 获取客户的回访记录详情
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/returnDetail.do")
	@ResponseBody
	public Map<String, Object> returnDetail(String id, HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		try {
			ReturnRecord retu = returnRecordService.getReturnRecordById(id);
			json.put("retu", retu);
			json.put("code", 1);

		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 获取客户的回访记录信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/returnList.do")
	@ResponseBody
	public Map<String, Object> returnList(String id, String userId, Integer limit, Integer page, String returnConent,
			HttpServletRequest request, HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户信息
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		PageInfo<ReturnRecord> pageInfo = new PageInfo<ReturnRecord>();
		try {
			if (userId == null || "-1".equals(userId)) {
				userId = user.getEmployeeId();
			}
			param.put("returnEmpId", userId);
			param.put("returnCustomerId", id);
			pageInfo.setPageNo(page);
			pageInfo.setPageSize(limit);
			if (Strings.isNotEmpty(returnConent)) {// 用户输入条件查询
				param.put("returnConent", returnConent);
			}
			PageInfo<ReturnRecord> pageRole = returnRecordService.getPageInfoList(param, pageInfo);
			json.put("total", pageRole.getPageCount());
			json.put("data", pageRole.getList());
			json.put("flag", 1);

		} catch (Exception e) {
			json.put("flag", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 跳转客户的收益记录界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toEraning.do")
	public ModelAndView toEraning(HttpServletRequest request, HttpSession session, String id) throws Exception {
		// 获取登录用户信息
		Employee user = (Employee) session.getAttribute("loginUser");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("personLiable", user.getEmployeeId());// 查询属于自己信息
		List<Customer> list = customerService.getCustomerList(map);
		map.put("customerId", id);// 根据用户ID和客户ID获取相关合同信息
		map.put("contractStatus", 4);// 根据用户ID和客户ID获取相关合同信息
		List<Contract> contractList = contractService.getContractList(map);
		request.setAttribute("contractList", contractList);
		request.setAttribute("customerList", list);
		request.setAttribute("customerId", id);
		return new ModelAndView("WEB-INF/jsp/customer/earningList");
	}

	/**
	 * 跳转经理查看员工客户的收益记录界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toEmployeeEraning.do")
	public ModelAndView toEmployeeEraning(HttpServletRequest request, HttpSession session, String id) throws Exception {
		request.setAttribute("empId", id);
		return new ModelAndView("WEB-INF/jsp/employee/earningList");
	}

	/**
	 * 获取客户的收益记录详情
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/eraningDetail.do")
	@ResponseBody
	public Map<String, Object> eraningDetail(String id, HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		try {
			EarningRecord eraning = earningRecordService.getEarningRecordById(id);
			json.put("eraning", eraning);
			json.put("code", 1);

		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 获取客户的收益记录信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/eraningList.do")
	@ResponseBody
	public Map<String, Object> eraningList(String id, String userId, Integer limit, Integer page, String contractNum,
			HttpServletRequest request, HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户信息
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		PageInfo<EarningRecord> pageInfo = new PageInfo<EarningRecord>();
		try {
			if (userId == null || "-1".equals(userId)) {
				userId = user.getEmployeeId();
			}
			param.put("employeeId", userId);
			param.put("customerId", id);
			pageInfo.setPageNo(page);
			pageInfo.setPageSize(limit);
			if (Strings.isNotEmpty(contractNum)) {// 用户输入条件查询
				param.put("contractNum", contractNum);
			}
			json.put("flag", "0");
			PageInfo<EarningRecord> pageRole = earningRecordService.getPageInfoList(param, pageInfo);
			json.put("total", pageRole.getPageCount());
			json.put("data", pageRole.getList());
			json.put("flag", 1);

		} catch (Exception e) {
			json.put("flag", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 跳转编辑合同信息界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/editContract.do")
	@ResponseBody
	public Map<String, Object> editContract(String id, HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id", id);

			Contract contract = contractService.getContractById(id);
			if (contract == null) {
				json.put("flag", 0);
				json.put("msg", "数据出现异常,请稍后再试!");
			} else {
				Customer customer = customerService.getCustomerById(contract.getCustomerId());
				json.put("flag", 1);
				json.put("contract", contract);
				json.put("customer", customer);
			}
		} catch (Exception e) {
			json.put("flag", -1);
			json.put("msg", "程序出错了!");
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 编辑合同登记记录
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/updateContract.do")
	@ResponseBody
	public Map<String, Object> updateContract(Contract contract, String date1, String date2, String date3,
			HttpServletRequest request, HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {
			// 获取登录用户
			Employee user = (Employee) session.getAttribute("loginUser");
			if (date1 != null && !date1.equals("")) {
				contract.setStartDate(stringToDate(date1));// 获取开始日期
			}
			if (date2 != null && !date2.equals("")) {
				contract.setEndDate(stringToDate(date2));// 获取结束日期
			}
			contractService.saveContract(contract, "修改", user);
			json.put("code", 1);
			json.put("contract", contract);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 跳转客户的合同登记界面
	 * 
	 * @param request
	 * @param
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toContract.do")
	public ModelAndView toContract(HttpServletRequest request, HttpSession session, String id) throws Exception {
		request.setAttribute("customerId", id);
		// 获取登录用户信息
		Employee user = (Employee) session.getAttribute("loginUser");
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("personLiable", user.getEmployeeId());// 查询属于自己的信息
		map.put("status", 0);// 查询属于自己的信息
		List<Customer> list = customerService.getCustomerList(map);
		List<Product> productList = productService.getProductList(map);// 获取所有产品信息
		request.setAttribute("productList", productList);
		request.setAttribute("customerList", list);
		return new ModelAndView("WEB-INF/jsp/customer/contractRegisterList");
	}

	/**
	 * 跳转经理查看员工客户的合同登记界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toEmployeeContract.do")
	public ModelAndView toEmployeeContract(HttpServletRequest request, HttpSession session, String id)
			throws Exception {
		request.setAttribute("empId", id);
		return new ModelAndView("WEB-INF/jsp/employee/contractRegisterList");
	}

	/**
	 * 跳转经理查看员工客户的合同登记界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toEmpContract.do")
	public ModelAndView toEmpContract(HttpServletRequest request, HttpSession session, String id, String employeeId)
			throws Exception {
		request.setAttribute("employeeId", employeeId);
		request.setAttribute("customerId", id);
		return new ModelAndView("WEB-INF/jsp/highseaspool/contractRegisterList");
	}

	/**
	 * 获取客户的合同登记信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/contractList.do")
	@ResponseBody
	public Map<String, Object> contractList(String id, String userId, Integer limit, Integer page, String contractNum,
			String isCheck, HttpServletRequest request, HttpSession session, HttpServletResponse response)
			throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		Employee user = (Employee) session.getAttribute("loginUser");
		PageInfo<Contract> pageInfo = new PageInfo<Contract>();
		try {
			if (Strings.isNotEmpty(contractNum)) {// 添加用户输入条件查询
				param.put("contractNum", contractNum);
			}
			pageInfo.setPageNo(page);
			pageInfo.setPageSize(limit);
			// 如果是审核列表查询，则增加标识
			if ("1".equals(isCheck)) {
				param.put("isCheck", isCheck);
				// 权限控制
				if (user.getQuarters().equals("1")) {
					param.put("teamId", user.getTeam().getBranchId());
				} else if (user.getQuarters().equals("2")) {
					param.put("branchId", user.getBranch().getBranchId());
				} else if (user.getQuarters().equals("3")) {
					param.put("deptId", user.getDept().getDeptId());
				}
			} else {
				if (userId == null || "-1".equals(userId)) {
					userId = user.getEmployeeId();
				}
				param.put("employeeId", userId);// 所属用户条件
				param.put("customerId", id);// 所属客户条件

			}
			PageInfo<Contract> pageRole = contractService.getPageInfoList(param, pageInfo);
			List<Customer> list = customerService.getCustomerList(param);
			json.put("total", pageRole.getPageCount());
			json.put("data", pageRole.getList());
			json.put("customer", list);
			json.put("flag", 1);

		} catch (Exception e) {
			json.put("flag", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 获取客户的合同登记信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/employeeContractList.do")
	@ResponseBody
	public Map<String, Object> employeeContractList(String id, String employeeId, Integer limit, Integer page,
			String contractNum, HttpServletRequest request, HttpSession session, HttpServletResponse response)
			throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		Employee user = (Employee) session.getAttribute("loginUser");
		PageInfo<Contract> pageInfo = new PageInfo<Contract>();
		try {
			if (Strings.isNotEmpty(contractNum)) {// 添加用户输入条件查询
				param.put("contractNum", contractNum);
			}
			pageInfo.setPageNo(page);
			pageInfo.setPageSize(limit);
			// 如果是审核列表查询，则增加标识
			param.put("employeeId", employeeId);// 所属客户条件
			param.put("customerId", id);// 所属客户条件
			PageInfo<Contract> pageRole = contractService.getPageInfoList(param, pageInfo);
			json.put("total", pageRole.getPageCount());
			json.put("data", pageRole.getList());
			json.put("code", 0);

		} catch (Exception e) {
			json.put("flag", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 跳转客户的跟进记录界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toFollow.do")
	public ModelAndView toFollow(HttpServletRequest request, HttpSession session, String id) throws Exception {
		request.setAttribute("customerId", id);
		return new ModelAndView("WEB-INF/jsp/customer/customerFollowList");
	}

	/**
	 * 跳转经理查看员工客户的跟进记录界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toEmployeeFollow.do")
	public ModelAndView toEmployeeFollow(HttpServletRequest request, HttpSession session, String id) throws Exception {
		request.setAttribute("empId", id);
		return new ModelAndView("WEB-INF/jsp/employee/customerFollowList");
	}

	/**
	 * 添加客户跟进记录
	 * 
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/insertCustomerFollow.do")
	@ResponseBody
	public Map<String, Object> insertCustomerFollow(CustomerFollowRecords customerFollow, String date,
			HttpServletRequest request, HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户
		try {
			// String savePath =
			// request.getSession().getServletContext().getRealPath("/");
			customerFollow.setCustomerFollowRecordsId(UUID.randomUUID().toString());// 获取UUID
			/*
			 * String path = "saituImage/"; if (customerFollow.getHotelImgFile()
			 * != null) { // 获取图片路径。 MyFileUploadUtils.saveFile(request,
			 * customerFollow.getHotelImgFile(), path);
			 * customerFollow.setPicture(path +
			 * request.getAttribute("picture").toString()); }
			 */
			if (customerFollow.getHotelImgFile() != null) {
				String path = "saituImage/";
				MyFileUploadUtils.saveFile(request, customerFollow.getHotelImgFile(), path);
				if (request.getAttribute("picture") != null) {
					customerFollow.setPicture(path + request.getAttribute("picture"));
				}
			}
			customerFollow.setCreateDate(new Date());// 获取创建时间
			if (date != null && !date.equals("")) {
				customerFollow.setFollowDate(stringToDateTime(date));// 获取跟进时间
			}
			customerFollow.setEmployeeName(user.getName());// 获取当前操作业务员名称
			customerFollow.setSection(user.getDept().getDeptId());// 获取所在部门ID
			customerFollow.setEmployeeId(user.getEmployeeId());// 获取业务员
			customerFollowRecordsService.saveCustomerFollowRecords(customerFollow, "新增");
			json.put("code", 1);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 客户跟进详情界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/followDetail.do")
	@ResponseBody
	public Map<String, Object> followDetail(String id, HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {
			CustomerFollowRecords cust = customerFollowRecordsService.getCustomerFollowRecordsById(id);
			json.put("cust", cust);
			json.put("code", 1);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 获取客户的跟进记录信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/followList.do")
	@ResponseBody
	public Map<String, Object> followList(String id, String userId, Integer limit, Integer page, String describe,
			HttpServletRequest request, HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		Employee user = (Employee) session.getAttribute("loginUser");
		PageInfo<CustomerFollowRecords> pageInfo = new PageInfo<CustomerFollowRecords>();
		try {
			if (userId == null || "-1".equals(userId)) {
				userId = user.getEmployeeId();
			}
			param.put("employeeId", userId);// 定义属于某个员工的条件
			param.put("customerId", id);// 定义属于某个客户的信息
			pageInfo.setPageNo(page);
			pageInfo.setPageSize(limit);
			if (Strings.isNotEmpty(describe)) {// 添加用户输入条件查询
				param.put("describe", describe);
			}
			PageInfo<CustomerFollowRecords> pageRole = customerFollowRecordsService.getCustomerFollowPageInfoList(param,
					pageInfo);
			json.put("total", pageRole.getPageCount());
			json.put("data", pageRole.getList());
			json.put("flag", "1");

		} catch (Exception e) {
			json.put("flag", "-1");
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 跳转客户拜访记录界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toVisit.do")
	public ModelAndView toVisit(HttpServletRequest request, HttpSession session, String id) throws Exception {
		request.setAttribute("customerId", id);
		return new ModelAndView("WEB-INF/jsp/customer/visitList");
	}

	/**
	 * 跳转经理查看员工客户拜访记录界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toEmployeeVisit.do")
	public ModelAndView toEmployeeVisit(HttpServletRequest request, HttpSession session, String id) throws Exception {
		request.setAttribute("empId", id);
		return new ModelAndView("WEB-INF/jsp/employee/visitList");
	}

	/**
	 * 添加客户拜访信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/insertVisit.do")
	@ResponseBody
	public Map<String, Object> insertVisit(VisitRecord visit, String date, HttpServletRequest request,
			HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {
			Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户
			if (date != null && !date.equals("")) {
				SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");
				visit.setVisitDate(formatter.parse(date));// 转换时间格式
			}
			visit.setVisitEmpId(user.getEmployeeId());// 写入创建用户名称
			visitRecordService.saveVisitRecord(visit, "新增");
			json.put("code", 1);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);

		}
		return json;
	}

	/**
	 * 客户拜访详情界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/visitDetail.do")
	@ResponseBody
	public Map<String, Object> visitDetail(String id, HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {
			VisitRecord visit = visitRecordService.getVisitRecordById(id);
			json.put("visit", visit);
			json.put("code", 1);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 获取客户的拜访记录信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/visitList.do")
	@ResponseBody
	public Map<String, Object> visitList(String id, String userId, HttpServletRequest request, HttpSession session,
			HttpServletResponse response, Integer limit, Integer page, String address) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户信息
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		PageInfo<VisitRecord> pageInfo = new PageInfo<VisitRecord>();
		try {
			if (userId == null || "-1".equals(userId)) {
				userId = user.getEmployeeId();
			}
			param.put("visitEmpId", userId); // 根据用户id查询
			param.put("visitCustomerId", id);// 根据客户id查询
			pageInfo.setPageNo(page);
			pageInfo.setPageSize(limit);
			if (Strings.isNotEmpty(address)) {// 添加用户输入查询条件
				param.put("visitAddress", address);
			}
			json.put("flag", "0");
			PageInfo<VisitRecord> pageRole = visitRecordService.getVisitRecordList(param, pageInfo);
			Employee emp = employeeService.getEmployeeById(userId.toString());
			json.put("emp", emp);
			json.put("total", pageRole.getPageCount());
			json.put("data", pageRole.getList());
			json.put("flag", "1");

		} catch (Exception e) {
			json.put("flag", "-1");
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 跳转客户主页界面
	 *
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toCustomer.do")
	public ModelAndView toCustomer(HttpSession session) throws Exception {
		return new ModelAndView("WEB-INF/jsp/customer/customerList");
	}

	/**
	 * 跳转客户主页界面
	 * 
	 * @param request
	 * @param
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toEmployeeInfo.do")
	public ModelAndView toEmployeeInfo(HttpServletRequest request, HttpSession session) throws Exception {
		try {
			Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户
			Map<String, Object> map = new HashMap<>();// 查询条件
			map.put("canNotReadAllMessage", false);
			List<Department> listDept = departmentService.getDepartmentList(map);
			List<Department> list = new ArrayList<Department>();// 返回list
			if (user.getQuarters().equals("5") || user.getQuarters().equals("6")) {// 有管理员或董事长权限
				Department dept = new Department();
				dept.setDeptName("全部分公司");
				dept.setRemake("滨海金控");
				list.add(dept);
				for (int i = 1; i <= listDept.size(); i++) {
					list.add(listDept.get(i - 1));
				}
			} else {// 有兼任部门
				map.put("employeeId", user.getEmployeeId());
				List<Pluralize> pluralizeList = pluralizeService.getPluralizeList(map);
				if (!user.getQuarters().equals("7") && !user.getQuarters().equals("8")) {
					list.add(user.getDept());
				}
				for (Pluralize pluralize : pluralizeList) {
					for (Department dept : listDept) {
						if (!pluralize.getDeptId().equals(user.getDept().getDeptId())) {
							if (pluralize.getDeptId().equals(dept.getDeptId())) {
								list.add(dept);
							}
						}
					}
				}
				if (list.size() == 0) {
					Department dept2 = new Department();
					dept2.setDeptName("-暂无数据-");
					dept2.setDeptId("99658");
					list.add(dept2);
				}
			}
			request.setAttribute("dept", list);
			return new ModelAndView("WEB-INF/jsp/employee/employeeList");
		} catch (Exception e) {
			logger.error("获取数据失败，原因：" + e);
			return new ModelAndView("WEB-INF/jsp/error/500");
		}
	}

	/**
	 * 获取用户所属的客户信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/customerList.do")
	@ResponseBody
	public Map<String, Object> customerList(HttpServletRequest request, HttpSession session,
			HttpServletResponse response, Integer limit, Integer page, String customerName, String deptId,
			String branchId, String teamId, String personLiable,String startDate,String endDate) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户信息
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		PageInfo<Customer> pageInfo = new PageInfo<Customer>();
		try {
			if (personLiable == null || personLiable == "") {
				personLiable = user.getEmployeeId();
			}
			param.put("personLiable", personLiable);// 负责人为自己
			pageInfo.setPageNo(page);
			pageInfo.setPageSize(limit);
			json.put("flag", "0");
			if (deptId != null && deptId != "") {// 所属分公司
				param.put("departmentId", deptId);
			}
			if (branchId != null && branchId != "") {// 所属部门
				param.put("branchId", branchId);
			}
			if (teamId != null && teamId != "") {// 所属团队
				param.put("teamId", teamId);
			}
			if (customerName != null && customerName != "") {// 添加用户输入查询条件
				param.put("customerName", customerName);
			}
			if (startDate != null && startDate != "") {// 添加用户输入查询条件
				param.put("startDate", startDate);
			}
			if (endDate != null && endDate != "") {// 添加用户输入查询条件
				param.put("endDate", endDate+" 23:59:59");
			}
			PageInfo<Customer> pageRole = customerService.getCustomerPageInfoList(param, pageInfo);
			json.put("total", pageRole.getPageCount());
			json.put("data", pageRole.getList());
			json.put("flag", "1");

		} catch (Exception e) {
			json.put("flag", "-1");
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 获取用户所属的客户信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/employeeCustomerList.do")
	@ResponseBody
	public Map<String, Object> employeeCustomerList(HttpServletRequest request, HttpSession session,
			HttpServletResponse response, Integer limit, Integer page, String customerName, String deptId,
			String branchId, String teamId, String personLiable,String startDate,String endDate) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户信息
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		PageInfo<Customer> pageInfo = new PageInfo<Customer>();
		try {
			if (personLiable == null || personLiable == "") {
				personLiable = user.getEmployeeId();
			}
			param.put("visitCustomerId", "true");// 查询客户被拜访次数
			param.put("personLiable", personLiable);// 负责人为自己
			pageInfo.setPageNo(page);
			pageInfo.setPageSize(limit);
			json.put("flag", "0");
			if (deptId != null && deptId != "") {// 所属分公司
				param.put("departmentId", deptId);
			}
			if (branchId != null && branchId != "") {// 所属部门
				param.put("branchId", branchId);
			}
			if (teamId != null && teamId != "") {// 所属团队
				param.put("teamId", teamId);
			}
			if (customerName != null && customerName != "") {// 添加用户输入查询条件
				param.put("customerName", customerName);
			}
			if (startDate != null && startDate != "") {// 添加用户输入查询条件
				param.put("startDate", startDate);
			}
			if (endDate != null && endDate != "") {// 添加用户输入查询条件
				param.put("endDate", endDate+" 23:59:59");
			}
			PageInfo<Customer> pageRole = customerService.getCustomerPageInfoList(param, pageInfo);
			for (Customer customer : pageRole.getList()) {
				if (customer.getMobileNumber() != null && customer.getMobileNumber() != "") {
					customer.setMobileNumber(customer.getMobileNumber().substring(0, 3) + "****"
							+ customer.getMobileNumber().substring(7, customer.getMobileNumber().length()));
				}
				if (customer.getIdNumber() != null && customer.getIdNumber() != ""
						&& customer.getIdNumber().length() == 18) {
					customer.setIdNumber(customer.getIdNumber().substring(0, 6) + "******"
							+ customer.getIdNumber().substring(13, customer.getIdNumber().length()));
				}
			}
			json.put("total", pageRole.getPageCount());
			json.put("data", pageRole.getList());
			json.put("flag", "1");

		} catch (Exception e) {
			json.put("flag", "-1");
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 获取用户所属的客户信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/customerMaterialList.do")
	@ResponseBody
	public Map<String, Object> customerMaterialList(HttpServletRequest request, HttpSession session,
			HttpServletResponse response, Integer limit, Integer page, String customerName, String deptId,
			String branchId, String teamId,String startDate,String endDate) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		PageInfo<Customer> pageInfo = new PageInfo<Customer>();
		try {
			if (checkPower(session, 89)) {
				pageInfo.setPageNo(page);
				pageInfo.setPageSize(limit);
				json.put("flag", "0");
				if (deptId != null && deptId != "") {// 所属分公司
					param.put("departmentId", deptId);
				}
				if (branchId != null && branchId != "") {// 所属部门
					param.put("branchId", branchId);
				}
				if (teamId != null && teamId != "") {// 所属团队
					param.put("teamId", teamId);
				}
				if (customerName != null && customerName != "") {// 添加用户输入查询条件
					param.put("customerName", customerName);
				}
				if (startDate != null && startDate != "") {// 添加用户输入查询条件
					param.put("startDate", startDate);
				}
				if (endDate != null && endDate != "") {// 添加用户输入查询条件
					param.put("endDate", endDate+" 23:59:59");
				}
				PageInfo<Customer> pageRole = customerService.getCustomerPageInfoList(param, pageInfo);
				json.put("total", pageRole.getPageCount());
				json.put("data", pageRole.getList());
				json.put("flag", "1");
			} else {
				json.put("flag", "-2");
			}
		} catch (Exception e) {
			json.put("flag", "-1");
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 移交用户所属的客户信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/transferCustomer.do")
	@ResponseBody
	public Map<String, Object> transferCustomer(HttpServletRequest request, HttpSession session,
			HttpServletResponse response, String batch, String personLiable, String devolveCustomerId)
			throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户信息
		Map<String, Object> map = new HashMap<String, Object>(); // 定义条件集合
		try {
			if (batch.equals("0")) {
				Customer customer = customerService.getCustomerById(devolveCustomerId);
				customer.setPersonLiable(personLiable);
				customerService.saveCustomer(customer, "修改");
			} else if (batch.equals("1")) {
				map.put("personLiable", user.getEmployeeId());
				List<Customer> list = customerService.getCustomerList(map);
				for (Customer cust : list) {
					cust.setPersonLiable(personLiable);
					customerService.saveCustomer(cust, "修改");
				}
			}
			json.put("code", 1);

		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 移交用户所属的客户信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/transferCustomerAdmin.do")
	@ResponseBody
	public Map<String, Object> transferCustomerAdmin(HttpServletRequest request, HttpSession session,
			HttpServletResponse response, String personLiable, String customerText) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户信息
		Map<String, Object> map = new HashMap<String, Object>(); // 定义条件集合
		try {
			String[] strList = customerText.split(",");
			map.put("personLiable", user.getEmployeeId());
			List<Customer> list = customerService.getCustomerList(map);
			for (String strId : strList) {
				Customer customer = new Customer();
				customer.setCustomerId(strId);
				customer.setPersonLiable(personLiable);
				customerService.saveCustomer(customer, "修改");
			}
			json.put("code", 1);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 跳转客户详情界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/customerDetail.do")
	public ModelAndView customerDetail(String id, HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		try {
			Customer customer = customerService.getCustomerById(id);
			request.setAttribute("customer", customer);
			return new ModelAndView("WEB-INF/jsp/customer/customerDetail");
		} catch (Exception e) {
			logger.error("获取数据失败，原因：" + e);
			return new ModelAndView("WEB-INF/jsp/error/500");
		}

	}

	/**
	 * 跳转添加客户信息界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/addCustomer.do")
	public ModelAndView addCustomer(String id, HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		return new ModelAndView("WEB-INF/jsp/customer/addCustomer");
	}

	/**
	 * 跳转编辑客户信息界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/editCustomer.do")
	@ResponseBody
	public Map<String, Object> editCustomer(String id, HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {

			Customer customer = customerService.getCustomerById(id);
			if (customer == null) {
				json.put("flag", 0);
				json.put("msg", "数据出现异常,请稍后再试!");
			} else {
				json.put("flag", 1);
				json.put("chance", customer);
			}
		} catch (Exception e) {
			json.put("flag", -1);
			json.put("msg", "操作失败请刷新后重试!");
			logger.error("获取数据失败，原因：" + e);
		}

		return json;
	}

	/**
	 * 跳转编辑客户信息界面
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/editEmployeeCustomer.do")
	@ResponseBody
	public Map<String, Object> editEmployeeCustomer(String id, HttpServletRequest request, HttpSession session,
			HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {

			Customer customer = customerService.getCustomerById(id);
			if (customer == null) {
				json.put("flag", 0);
				json.put("msg", "数据出现异常,请稍后再试!");
			} else {
				if (customer.getMobileNumber() != null && customer.getMobileNumber() != "") {
					customer.setMobileNumber(customer.getMobileNumber().substring(0, 3) + "****"
							+ customer.getMobileNumber().substring(7, customer.getMobileNumber().length()));
				}
				if (customer.getIdNumber() != null && customer.getIdNumber() != ""
						&& customer.getIdNumber().length() == 18) {
					customer.setIdNumber(customer.getIdNumber().substring(0, 6) + "******"
							+ customer.getIdNumber().substring(13, customer.getIdNumber().length()));
				}
				json.put("flag", 1);
				json.put("chance", customer);
			}
		} catch (Exception e) {
			json.put("flag", -1);
			json.put("msg", "操作失败请刷新后重试!");
			logger.error("获取数据失败，原因：" + e);
		}

		return json;
	}

	/**
	 * 添加客户信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/insertCustomer.do")
	@ResponseBody
	public Map<String, Object> insertCustomer(Customer customer, String date, HttpServletRequest request,
			HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {
			if (customer.getMobileNumber() != null) {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("mobileNumber", customer.getMobileNumber());
				if (customer.getIdNumber() != null && !customer.getIdNumber().equals("")) {
					map.put("idNumber", customer.getIdNumber());
				}
				Customer validateCustomer = customerService.validateCustomer(map);
				if (validateCustomer != null) {
					json.put("name", validateCustomer.getEmp().getName());
					json.put("code", -2);
					return json;
				}
			}
			// 获取登录用户
			Employee user = (Employee) session.getAttribute("loginUser");
			String strId = UUID.randomUUID().toString();
			customer.setCustomerId(strId);// 获取UUID
			if (date != null && !date.equals("")) {
				customer.setBirthday(stringToDate(date));
			}
			String path = "saituImage/";
			if (customer.getHotelImgFile() != null) {
				// 获取图片路径。
				if (MyFileUploadUtils.saveFile(request, customer.getHotelImgFile(), path)) {
					customer.setPicture(path + request.getAttribute("picture").toString());
				}

			}

			List<Document> list = new ArrayList<Document>();
			if (customer.getHotelImgFileList() != null) {
				String path2 = "upload/";
				for (MultipartFile MultipartFile : customer.getHotelImgFileList()) {
					MyFileUploadUtils.saveFile(request, MultipartFile, path2);
					if (request.getAttribute("picture") != null) {
						Document document = new Document();
						document.setRecordId(strId);
						document.setType("3");
						document.setUrl(path2 + request.getAttribute("picture"));
						document.setNewName(request.getAttribute("picture").toString());
						document.setName(MultipartFile.getOriginalFilename());
						list.add(document);
					}
				}
			}
			customer.setCreateDate(new Date());// 获取创建时间
			customer.setCreatePeople(user.getEmployeeId());// 获取创建人
			if (user.getDept() != null) {
				customer.setDepartmentId(user.getDept().getDeptId());//// 获取所属部门，默认为创建人所在部门
			}
			customer.setPersonLiable(user.getEmployeeId());// 获取负责人，默认为创建人
			if (user.getBranch() != null) {
				customer.setBranchId(user.getBranch().getBranchId());
			}
			if (user.getTeam() != null) {
				customer.setTeamId(user.getTeam().getBranchId());
			}
			customer.setCustomerState("0");
			if (customerService.saveCustomer(customer, "新增") > 0) {
				if (list.size() > 0) {
					documentService.addDocumentList(list);
				}
				json.put("code", 0);
			} else {
				json.put("code", 1);
			}
		} catch (Exception e) {
			logger.error("获取数据失败，原因：" + e);
			json.put("code", -1);
		}
		return json;
	}

	/**
	 * 修改客户信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/updateCustomer.do")
	@ResponseBody
	public Map<String, Object> updateCustomer(Customer customer, String date, HttpServletRequest request,
			HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>();
		try {
			if (customer.getMobileNumber() != null) {
				Map<String, Object> map = new HashMap<String, Object>();
				map.put("mobileNumber", customer.getMobileNumber());
				if (customer.getIdNumber() != null && !customer.getIdNumber().equals("")) {
					map.put("idNumber", customer.getIdNumber());
				}
				map.put("customerId", customer.getCustomerId());
				Customer validateCustomer = customerService.validateCustomer(map);
				if (validateCustomer != null) {
					json.put("name", validateCustomer.getEmp().getName());
					json.put("code", -2);
					return json;
				}
			}
			// 获取登录用户
			Employee user = (Employee) session.getAttribute("loginUser");
			if (date != null && !date.equals("")) {
				customer.setBirthday(stringToDate(date));
			}
			String path = "saituImage/";
			if (customer.getFileName() != null && !customer.getFileName().equals("")) {
				if (customer.getHotelImgFile() != null) {
					// 获取图片路径。
					if (MyFileUploadUtils.saveFile(request, customer.getHotelImgFile(), path)) {
						customer.setPicture(path + request.getAttribute("picture").toString());
					}

				}
			}
			List<Document> list = new ArrayList<Document>();
			if (customer.getHotelImgFileList() != null) {
				String path2 = "upload/";
				for (MultipartFile MultipartFile : customer.getHotelImgFileList()) {
					MyFileUploadUtils.saveFile(request, MultipartFile, path2);
					if (request.getAttribute("picture") != null) {
						Document document = new Document();
						document.setRecordId(customer.getCustomerId());
						document.setType("3");
						document.setUrl(path2 + request.getAttribute("picture"));
						document.setNewName(request.getAttribute("picture").toString());
						document.setName(MultipartFile.getOriginalFilename());
						list.add(document);
					}
				}
			}
			customer.setUpdatePeople(user.getName());
			customer.setUpdateDate(new Date());
			if (customerService.saveCustomer(customer, "修改") > 0) {
				if (list.size() > 0) {
					documentService.deleteDocumentById(customer.getCustomerId());
					documentService.addDocumentList(list);
				}
				json.put("code", 0);
			} else {
				json.put("code", 1);
			}
			json.put("code", 0);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}

	/**
	 * 跳转客户生日主页界面
	 * 
	 * @param request
	 * @param
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/toCustomerBirthdayList.do")
	public ModelAndView toCustomerBirthdayList(HttpServletRequest request, HttpSession session) throws Exception {
		try {
			Employee user = (Employee) session.getAttribute("loginUser");
			Map<String, Object> map = new HashMap<>();
			List<Department> list = new ArrayList<Department>();
			map.put("canNotReadAllMessage", false);
			List<Department> listDept = departmentService.getDepartmentList(map);// 查询所有部门
			if (checkPower(session, 92)) {
				map.put("canNotReadAllMessage", false);
				list = departmentService.getDepartmentList(map);// 查询所有部门
				request.setAttribute("isDept", true);// 标识是否有特殊权限
				request.setAttribute("dept", list);
			} else if (checkPower(session, 80)) {
				map.put("employeeId", user.getEmployeeId());
				List<Pluralize> pluralizeList = pluralizeService.getPluralizeList(map);
				if (!user.getQuarters().equals("7") && !user.getQuarters().equals("8")) {
					list.add(user.getDept());
				}
				for (Pluralize pluralize : pluralizeList) {
					for (Department dept : listDept) {
						if (!pluralize.getDeptId().equals(user.getDept().getDeptId())) {
							if (pluralize.getDeptId().equals(dept.getDeptId())) {
								list.add(dept);
							}
						}
					}
				}
				if (list.size() == 0) {
					Department dept2 = new Department();
					dept2.setDeptName("-暂无数据-");
					dept2.setDeptId("99658");
					list.add(dept2);
				}
				request.setAttribute("isDept", true);// 标识是否有特殊权限
				request.setAttribute("dept", list);
			}
			return new ModelAndView("WEB-INF/jsp/customer/birthdayList");
		} catch (Exception e) {
			logger.error("获取数据失败，原因：" + e);
			return new ModelAndView("WEB-INF/jsp/error/500");
		}
	}

	/**
	 * AJAX 异步 获取分公司
	 * 
	 * @param request
	 * @param response
	 * @return 1成功 -1异常 0失败
	 */
	@RequestMapping("getBirthdayDeptInfo.do")
	@ResponseBody
	public Map<String, Object> getDeptInfo(HttpSession session, HttpServletRequest request,
			HttpServletResponse response) {
		Map<String, Object> json = new HashMap<String, Object>();
		try {
			Employee user = (Employee) session.getAttribute("loginUser");
			Map<String, Object> map = new HashMap<>();
			List<Department> list = new ArrayList<Department>();
			map.put("canNotReadAllMessage", false);
			List<Department> listDept = departmentService.getDepartmentList(map);// 查询所有部门
			if (checkPower(session, 92)) {
				map.put("canNotReadAllMessage", false);
				list = departmentService.getDepartmentList(map);// 查询所有部门
				json.put("quar", "quar");
			} else if (checkPower(session, 80)) {
				map.put("employeeId", user.getEmployeeId());
				List<Pluralize> pluralizeList = pluralizeService.getPluralizeList(map);
				if (!user.getQuarters().equals("7") && !user.getQuarters().equals("8")) {
					list.add(user.getDept());
				}
				for (Pluralize pluralize : pluralizeList) {
					for (Department dept : listDept) {
						if (!pluralize.getDeptId().equals(user.getDept().getDeptId())) {
							if (pluralize.getDeptId().equals(dept.getDeptId())) {
								list.add(dept);
							}
						}
					}
				}
			}else{
				list.add(user.getDept());
			}
			if (list.size() == 0) {
				Department dept2 = new Department();
				dept2.setDeptName("-暂无数据-");
				dept2.setDeptId("99658");
				list.add(dept2);
			}
			json.put("data", list);
			json.put("code", 0);
		} catch (Exception e) {
			logger.error("获取数据失败，原因：" + e);
			json.put("code", -1);
		}
		return json;
	}
	/**
	 * 获取用户所属的客户信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/customerBirthdayList.do")
	@ResponseBody
	public Map<String, Object> customerBirthdayList(HttpServletRequest request, HttpSession session,
			HttpServletResponse response, Integer limit, Integer page, String customerName, String deptId)
			throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户信息
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		Map<String, Object> map = new HashMap<String, Object>();// 定义条件集合
		PageInfo<Customer> pageInfo = new PageInfo<Customer>();
		try {
			if (checkPower(session, 92)) {
				param.put("personLiable", null);// 查询全部近期生日的客户信息
			} else if (checkPower(session, 80)) {
				param.put("personLiable", null);// 查询兼任部门近期生日的客户信息
				String birthdayDepartmentId = "";
				map.put("employeeId", user.getEmployeeId());
				List<Pluralize> pluralizeList = pluralizeService.getPluralizeList(map);
				for (Pluralize pluralize : pluralizeList) {
					birthdayDepartmentId += "\"" + pluralize.getDeptId() + "\",";
				}
				if(birthdayDepartmentId.length()>0){
					param.put("birthdayDepartmentId", birthdayDepartmentId.substring(0, birthdayDepartmentId.length() - 1));// 负责人为自己
				}else{
					param.put("birthdayDepartmentId","\"NO DATA\"");// 没有兼任
				}
			} else {
				param.put("personLiable", user.getEmployeeId());// 负责人为自己

			}
			param.put("departmentId", deptId);
			param.put("birthday", "birthday");
			pageInfo.setPageNo(page);
			pageInfo.setPageSize(limit);
			if (customerName != null && customerName != "") {// 添加用户输入查询条件
				param.put("customerName", customerName);
			}
			PageInfo<Customer> pageRole = customerService.getCustomerPageInfoList(param, pageInfo);
			json.put("total", pageRole.getPageCount());
			json.put("data", pageRole.getList());
			json.put("flag", "1");

		} catch (Exception e) {
			json.put("flag", "-1");
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 获取用户所属的客户信息
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/customerBirthdayCount.do")
	@ResponseBody
	public Map<String, Object> customerBirthdayCount(HttpServletRequest request, HttpSession session,
			HttpServletResponse response, String customerName) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户信息
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		Map<String, Object> map = new HashMap<String, Object>();// 定义条件集合
		try {
			if (checkPower(session, 92)) {
				param.put("personLiable", null);// 查询全部近期生日的客户信息
			} else if (checkPower(session, 80)) {
				param.put("personLiable", null);// 查询兼任部门近期生日的客户信息
				String birthdayDepartmentId = "";
				if (!user.getQuarters().equals("7") && !user.getQuarters().equals("8")) {
					birthdayDepartmentId += "\"" + user.getDept().getDeptId() + "\",";
				}
				map.put("employeeId", user.getEmployeeId());
				List<Pluralize> pluralizeList = pluralizeService.getPluralizeList(map);
				for (Pluralize pluralize : pluralizeList) {
					birthdayDepartmentId += "\"" + pluralize.getDeptId() + "\",";
				}
				if(birthdayDepartmentId.length()>0){
					param.put("birthdayDepartmentId", birthdayDepartmentId.substring(0, birthdayDepartmentId.length() - 1));// 负责人为自己
				}else{
					param.put("birthdayDepartmentId","\"NO DATA\"");// 没有兼任
				}
			} else {
				param.put("personLiable", user.getEmployeeId());// 负责人为自己

			}
			param.put("birthday", "birthday");
			if (customerName != null && customerName != "") {// 添加用户输入查询条件
				param.put("customerName", customerName);
			}
			Integer count = customerService.getBirthdayCount(param);
			json.put("count", count);
			json.put("code", "1");
		} catch (Exception e) {
			json.put("code", "-1");
			logger.error("获取数据失败，原因：" + e);
		}

		return json;

	}

	/**
	 * 通讯录导入客户
	 * 
	 * @return
	 */
	@RequestMapping("/importContacts.do")
	@ResponseBody
	public Map<String, Object> importContacts(HttpServletRequest request, HttpSession session, String customerText) {
		Map<String, Object> json = new HashMap<String, Object>();
		Employee user = (Employee) session.getAttribute("loginUser");// 获取登录用户
		List<Customer> addList = new ArrayList<Customer>();
		Map<String, Object> map = new HashMap<String, Object>();
		String phone = request.getParameter("phone");
		map.put("checkPhone", phone.substring(0, phone.length() - 1));
		try {
			List<Customer> customerList = customerService.getCustomerList(map);// 获取全部客户
			JSONArray jsonObj = new JSONArray(customerText);
			for (int i = 0; i < jsonObj.length(); i++) {
				Customer contacs = new Customer();
				JSONObject jsons = (JSONObject) jsonObj.get(i);
				contacs.setCustomerName(jsons.get("customerName").toString());
				contacs.setMobileNumber(jsons.get("mobileNumber").toString());
				contacs.setSex("男");
				contacs.setAddress("");
				contacs.setProfession("");
				contacs.setCustomerType("0");
				contacs.setCustomerId(UUID.randomUUID().toString());// 创建客户ID
				contacs.setCreatePeople(user.getName());// 创建人姓名
				contacs.setCreateDate(new Date());// 创建时间
				contacs.setCustomerState("0");// 客户状态为有效
				contacs.setPersonLiable(user.getEmployeeId());// 所属员工
				if (customerList.size() > 0) {
					for (Customer customer : customerList) {
						if (!customer.getMobileNumber().equals(jsons.get("mobileNumber").toString())) {
							addList.add(contacs);
						}
					}
				} else {
					addList.add(contacs);
				}
			}
			customerService.addCustomerList(addList);
			if (customerList.size() > 0) {
				json.put("data", customerList);
				json.put("code", -2);
			} else {
				json.put("code", 0);
			}
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 获取客户数量
	 * 
	 * @return
	 */
	@RequestMapping("/getCustomerCount.do")
	@ResponseBody
	public Map<String, Object> getCustomerCount(HttpServletRequest request, HttpSession session, String empId) {
		Map<String, Object> json = new HashMap<String, Object>();
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("personLiable", empId);
		try {
			int count = customerService.countCustomer(map);
			json.put("count", count);
			json.put("code", 0);
		} catch (Exception e) {
			json.put("code", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;

	}

	/**
	 * 获取产品的预约信息列表
	 * 
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping("/bespeakList.do")
	@ResponseBody
	public Map<String, Object> bespeakList(Integer limit, Integer page, String contractNum, String isCheck,
			HttpServletRequest request, HttpSession session, HttpServletResponse response) throws Exception {
		Map<String, Object> json = new HashMap<String, Object>(); // 定义返回map集合
		Map<String, Object> param = new HashMap<String, Object>();// 定义条件集合
		Employee user = (Employee) session.getAttribute("loginUser");
		PageInfo<Contract> pageInfo = new PageInfo<Contract>();
		try {
			if (Strings.isNotEmpty(contractNum)) {// 添加用户输入条件查询
				param.put("contractNum", contractNum);
			}
			pageInfo.setPageNo(page);
			pageInfo.setPageSize(limit);
			// 如果是审核列表查询，则增加标识
			param.put("contractStatus", "5");
			// 权限控制
			if (user.getQuarters().equals("1")) {
				param.put("teamId", user.getTeam().getBranchId());
			} else if (user.getQuarters().equals("2")) {
				param.put("branchId", user.getBranch().getBranchId());
			} else if (user.getQuarters().equals("3")) {
				param.put("deptId", user.getDept().getDeptId());
			}
			PageInfo<Contract> pageRole = contractService.getPageInfoList(param, pageInfo);
			// List<Customer> list = customerService.getCustomerList(param);
			json.put("total", pageRole.getPageCount());
			json.put("data", pageRole.getList());
			// json.put("customer", list);
			json.put("flag", 1);

		} catch (Exception e) {
			json.put("flag", -1);
			logger.error("获取数据失败，原因：" + e);
		}
		return json;
	}
}
